home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Magazine Collection 2001
/
Delphi Magazine Collection 20001 (2001).iso
/
DISKS
/
ISSUE09
/
SAFELIST
/
MAINFORM.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1996-03-20
|
2KB
|
91 lines
unit Mainform;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, ExtCtrls, Shapes;
type
TForm1 = class(TForm)
Label1: TLabel;
ShapeRadioGroup: TRadioGroup;
SizeEdit: TEdit;
PaintBox: TPaintBox;
AddBtn: TButton;
Label2: TLabel;
TopEdit: TEdit;
Label3: TLabel;
ColourComboBox: TComboBox;
Left: TLabel;
LeftEdit: TEdit;
procedure AddBtnClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormPaint(Sender: TObject);
private
ShapeList : TShapeList;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
{Ensure a colour is selected}
ColourComboBox.ItemIndex := 0;
{Create the list that will hold all the shapes to draw}
ShapeList := TShapeList.Create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
var
i : Integer;
begin
{Free the list and all the shapes it contains, because Free calls Destroy if
ShapeList was successfully created, and TShapeList.Destroy now cleans up
after itself.}
ShapeList.Free;
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
{Redraw all the shapes}
ShapeList.DrawAllShapes(PaintBox.Canvas);
end;
procedure TForm1.AddBtnClick(Sender: TObject);
const
Colours : array[0..2] of TColor = (clRed,clGreen,clBlue);
var
NewShape : TMyShape;
begin
{Create a new shape object based on the radio button selection}
case ShapeRadioGroup.ItemIndex of
0 : NewShape := TCircle.Create;
1 : NewShape := TSquare.Create;
end;
{Set the properties of the new shape}
NewShape.Size := StrToInt(SizeEdit.Text);
NewShape.Top := StrToInt(TopEdit.Text);
NewShape.Left := StrToInt(LeftEdit.Text);
NewShape.Colour := Colours[ColourComboBox.ItemIndex];
{Add the shape to the list of shapes}
ShapeList.Add(NewShape);
{Redraw everything in the list, as the new shape may cover old ones}
ShapeList.DrawAllShapes(PaintBox.Canvas);
end;
end.